import axios from "axios";
import { message } from "ant-design-vue";

const axiosRequest = axios.create({
    baseURL:  "/api/",    // baseUrl + url = 请求地址
    timeout: 5000,
})

//添加相应拦截器，将response中的其他属性去除，只保留data返回给调用者
axiosRequest.interceptors.response.use(response => {
        const newResponse = response.data;
        if (newResponse.code === '200') {
            return newResponse;
        } else {
            message.error(newResponse.msg);
            return Promise.reject(new Error(newResponse.message || '请求失败'));
        }
    }
)

export default axiosRequest;